package mamma.action;

import java.io.File;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import mamma.common.FileService;
import mamma.dao.jinhyukDao;
import mamma.vo.BannerVo;
import mamma.vo.MemberVo;
import mamma.vo.InformationVo;


//import mamma.vo.jusaVO;


import mamma.vo.VaccinationVo;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class jinhyukAction extends ActionSupport {
	
	 private int id;
	 private String infoName;
	 private String infoContent;
	 private String year;
	 private String month;
	 private String day;
	 private String startDate;
	 private String eyear;
	 private String emonth;
	 private String eday;
	 private String endDate;
	 private int importance;
	 private List<InformationVo> list;
	 private InformationVo info;
	 private String adminId;

	 
	 private String title;
	 private String content;
	 private String startMonth;
	 private String endMonth;
	 private List<VaccinationVo> jlist;
	 private VaccinationVo vac;
	 
	 private String email;
	 private List<MemberVo> mlist;
	 private File upload;
	 private String uploadFileName;
	 private String uploadContentType;
	 private BannerVo banner;
	 private HttpServletRequest request;
	 private String savedFile;
	 private List<BannerVo> bannerList;
	 private String link;
	  
	 
	 
	 public String baup() throws Exception{
		      //프로필로 등록한 사진 서버에 업로드
		   	System.out.println("bbbbbbbbbbbbbbbbbbbbbbb"+link);
		   	System.out.println("aaaaaaaaaaaaaaaaaaaaaa"+id);
		   	System.out.println("aaaaaaaaaaaaaaaaaaaaaa"+upload);
		   	System.out.println("aaaaaaaaaaaaaaaaaaaaaa"+uploadFileName);
		   	  banner = new BannerVo();
		      FileService fs = new FileService();
		      String basePath = ServletActionContext.getServletContext().getRealPath("/photoData");
		            
		      String savedfile = fs.saveFile(upload, basePath, uploadFileName);
		      banner.setSavedFile(savedfile);
		      banner.setOriginalFile(uploadFileName);
		   
		      banner.setLink(link);
		      banner.setId(id);
		      System.out.println("11111111111111"+banner+"11111111111111111");
		      
		      jinhyukDao dao = new jinhyukDao();
		      dao.insertbanner(banner);
		      
		      return SUCCESS;
		   }
	   
	   
	   public String bade() throws Exception {
		   System.out.println("aaaaaaaaaaaaaaaaaaaaaa"+id);
		   
		   System.out.println("bbbbbbbbbbbbbbbbbbbbbbb"+link);		   			  
		
		   	banner = new BannerVo();
		    
		   	banner.setSavedFile(link);
		    banner.setOriginalFile(link);
		    banner.setLink(link);
		    banner.setId(id);
		      System.out.println("11111111111111"+banner+"11111111111111111");
		      
		      jinhyukDao dao = new jinhyukDao();
		      dao.bade(banner);
			return SUCCESS;
		}
	   
	   public String baget() throws Exception {
			System.out.println("배너1아이디 불러왔음?" + id);

			jinhyukDao dao = new jinhyukDao();	
			banner = dao.baget(id);
			System.out.println("111111111"+banner+"1111111111");
			return SUCCESS;
		}	
	 
	 public String nwrite() throws Exception {
		 	 System.out.println("저장시작??");
		 	
		 	ActionContext context = ActionContext.getContext();
			Map<String, Object>session = (Map<String, Object>)context.getSession();
			MemberVo temp = (MemberVo)session.get("login");
			adminId = temp.getEmail();
			
			System.out.println("아이디옴???"+adminId);
			
			String startDate = year + "/" + month + "/" + day;
			String endDate = eyear + "/" + emonth + "/" + eday;
			
			System.out.println(startDate+"날짜??"+startDate);
			
			jinhyukDao dao = new jinhyukDao();		
			InformationVo info = new InformationVo();
			info.setId(id);
			info.setAdminId(adminId);
			info.setStartDate(startDate);
			info.setEndDate(endDate);
			info.setInfoName(infoName);
			info.setInfoContent(infoContent);
			info.setImportance(importance);
			
			dao.nwrite(info);
			
			System.out.println("저장됨??");

			return SUCCESS;
		}
	 
	  public String gList() throws Exception {

			System.out.println("리스트불러오기???");
			
			ActionContext context = ActionContext.getContext();
			Map<String, Object>session = (Map<String, Object>)context.getSession();
			MemberVo temp = (MemberVo)session.get("login");
			adminId = temp.getEmail();
			
			jinhyukDao dao = new jinhyukDao();	
			
			list = dao.list(adminId);

			return SUCCESS;
		}
	 
	  public String read() throws Exception {
			System.out.println("readdddddddd" + id);

			jinhyukDao dao = new jinhyukDao();	
			info = dao.read(id);
			System.out.println("111111111"+info+"1111111111");
			return SUCCESS;
		}
	  
	  public String read2() throws Exception {
			

			jinhyukDao dao = new jinhyukDao();	
			info = new InformationVo();
			info = dao.read(id);
			
			startDate = info.getStartDate();
			year = startDate.substring(0,4);
			month = startDate.substring(5, 7);
			day = startDate.substring(8, 10);
			info.setYear(year);
			info.setMonth(month);
			info.setDay(day);
			
			endDate = info.getEndDate();
			eyear = endDate.substring(0,4);
			emonth = endDate.substring(5, 7);
			eday = endDate.substring(8, 10);
			info.setEyear(eyear);
			info.setEmonth(emonth);
			info.setEday(eday);
			
			System.out.println("111111111"+info+"1111111111");
			return SUCCESS;
		}
	  
	  public String update() throws Exception {
		 	 System.out.println("저장시작??");
		 	
			
			String startDate = year + "/" + month + "/" + day;
			String endDate = eyear + "/" + emonth + "/" + eday;
			
			System.out.println(startDate+"날짜??"+startDate);
			
			jinhyukDao dao = new jinhyukDao();		
			InformationVo info = new InformationVo();
			info.setId(id);
			info.setAdminId(adminId);
			info.setStartDate(startDate);
			info.setEndDate(endDate);
			info.setInfoName(infoName);
			info.setInfoContent(infoContent);
			info.setImportance(importance);
			
			dao.update(info);
			
			System.out.println("저장됨??");

			return SUCCESS;
		}
	  
	  public String ndelete() throws Exception {
			System.out.println(id+"이걸삭제하자");
		  	jinhyukDao dao = new jinhyukDao();	
			dao.ndelete(id);
			System.out.println("삭제됨");
			return SUCCESS;
		}

	 
	 public String jusa() throws Exception {
			
			jinhyukDao dao = new jinhyukDao();		
			VaccinationVo jusa = new VaccinationVo();
			jusa.setId(id);
			jusa.setStartMonth(startMonth);
			jusa.setEndMonth(endMonth);
			jusa.setTitle(title);
			jusa.setContent(content);
			
			dao.jusa(jusa);
			
			System.out.println("주사저장됨??");

			return SUCCESS;
		}
	 
	 public String gjList() throws Exception {

			System.out.println("주사리스트불러오기???");
			
			jinhyukDao dao = new jinhyukDao();	
			jlist = dao.jlist();
			
			System.out.println(jlist + "리스트불러옴?");
			
			return SUCCESS;
		}
	 
	  public String jread() throws Exception {
			System.out.println("read" + id);

			jinhyukDao dao = new jinhyukDao();	
			vac = dao.jread(id);
			System.out.println("111111111"+vac+"1111111111");
			return SUCCESS;
		}

	  public String jupdate() throws Exception {
		 	
		  	System.out.println("저장시작??");
		 	
			
		 	jinhyukDao dao = new jinhyukDao();		
			VaccinationVo jusa = new VaccinationVo();
			jusa.setId(id);
			jusa.setStartMonth(startMonth);
			jusa.setEndMonth(endMonth);
			jusa.setTitle(title);
			jusa.setContent(content);
			
			System.out.println("주사목록"+ jusa + "목로옥");
			
			dao.jupdate(jusa);
			
			System.out.println("저장됨??");

			return SUCCESS;
		}
	  
	  public String jdelete() throws Exception {
			System.out.println(id+"j이걸삭제하자");
		  	jinhyukDao dao = new jinhyukDao();	
			dao.jdelete(id);
			System.out.println("j삭제됨");
			return SUCCESS;
		}
	  
	  public String mlist() throws Exception {

			System.out.println("멤버리스트불러오기???");
	
			
			jinhyukDao dao = new jinhyukDao();				
			mlist = dao.mlist();

			return SUCCESS;
		}
	  
	  public String mdelete() throws Exception {
			System.out.println(email+"m이걸삭제하자");
		  	jinhyukDao dao = new jinhyukDao();	
			dao.mdelete(email);
			System.out.println("m삭제됨");
			return SUCCESS;
		}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getInfoName() {
		return infoName;
	}

	public void setInfoName(String infoName) {
		this.infoName = infoName;
	}

	public String getInfoContent() {
		return infoContent;
	}

	public void setInfoContent(String infoContent) {
		this.infoContent = infoContent;
	}

	public String getYear() {
		return year;
	}

	public void setYear(String year) {
		this.year = year;
	}

	public String getMonth() {
		return month;
	}

	public void setMonth(String month) {
		this.month = month;
	}

	public String getDay() {
		return day;
	}

	public void setDay(String day) {
		this.day = day;
	}

	public String getStartDate() {
		return startDate;
	}

	public void setStartDate(String startDate) {
		this.startDate = startDate;
	}

	public int getImportance() {
		return importance;
	}

	public void setImportance(int importance) {
		this.importance = importance;
	}

	public String getAdminId() {
		return adminId;
	}

	public void setAdminId(String adminId) {
		this.adminId = adminId;
	}

	public InformationVo getInfo() {
		return info;
	}

	public void setInfo(InformationVo info) {
		this.info = info;
	}

	public String getEyear() {
		return eyear;
	}

	public void setEyear(String eyear) {
		this.eyear = eyear;
	}

	public String getEmonth() {
		return emonth;
	}

	public void setEmonth(String emonth) {
		this.emonth = emonth;
	}

	public String getEday() {
		return eday;
	}

	public void setEday(String eday) {
		this.eday = eday;
	}

	public String getEndDate() {
		return endDate;
	}

	public void setEndDate(String endDate) {
		this.endDate = endDate;
	}

	public List<InformationVo> getList() {
		return list;
	}

	public void setList(List<InformationVo> list) {
		this.list = list;
	}


	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getStartMonth() {
		return startMonth;
	}

	public void setStartMonth(String startMonth) {
		this.startMonth = startMonth;
	}

	public String getEndMonth() {
		return endMonth;
	}

	public void setEndMonth(String endMonth) {
		this.endMonth = endMonth;
	}

	public List<VaccinationVo> getJlist() {
		return jlist;
	}

	public void setJlist(List<VaccinationVo> jlist) {
		this.jlist = jlist;
	}

	public VaccinationVo getVac() {
		return vac;
	}

	public void setVac(VaccinationVo vac) {
		this.vac = vac;
	}

	public List<MemberVo> getMlist() {
		return mlist;
	}

	public void setMlist(List<MemberVo> mlist) {
		this.mlist = mlist;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}


	public File getUpload() {
		return upload;
	}


	public void setUpload(File upload) {
		this.upload = upload;
	}


	public String getUploadFileName() {
		return uploadFileName;
	}


	public void setUploadFileName(String uploadFileName) {
		this.uploadFileName = uploadFileName;
	}


	public String getUploadContentType() {
		return uploadContentType;
	}


	public void setUploadContentType(String uploadContentType) {
		this.uploadContentType = uploadContentType;
	}


	public BannerVo getBanner() {
		return banner;
	}


	public void setBanner(BannerVo banner) {
		this.banner = banner;
	}


	public HttpServletRequest getRequest() {
		return request;
	}


	public void setRequest(HttpServletRequest request) {
		this.request = request;
	}


	public String getSavedFile() {
		return savedFile;
	}


	public void setSavedFile(String savedFile) {
		this.savedFile = savedFile;
	}


	public List<BannerVo> getBannerList() {
		return bannerList;
	}


	public void setBannerList(List<BannerVo> bannerList) {
		this.bannerList = bannerList;
	}


	public String getLink() {
		return link;
	}


	public void setLink(String link) {
		this.link = link;
	}
	
	
 
}
